var ns;
var app = new Vue({
    el: '#app',
    data: {
        roominfo: {
            RoomID: '',
            FullName: "",
            Name: "",
            RoomStateName: "",
            RoomStateID: 0,
            RelationName: "",
            RelatePhoneNumber: "",
            BuildingArea: 0,
            BuildOutArea: 0
        },
        ID: 0,
        statelist: [],
        staticData: true,
        dynamicData: false,
        isActive: false,
    },
    methods: {
        edit: function() {
            var that = this;
            that.isActive = true;
            that.dynamicData = true;
            that.staticData = false;

        },
        save:function(){
          var that = this;
          var options = {
              action: 'viewroomfileadd',
              ID: app.ID,
              Name: that.roominfo.Name,
              RoomState: that.roominfo.RoomStateID,
              RelationName: that.roominfo.RelationName,
              RelatePhoneNumber: that.roominfo.RelatePhoneNumber,
              statename: that.statelist.RoomStateName,
              BuildingArea:that.roominfo.BuildingArea,
              BuildOutArea:that.roominfo.BuildOutArea,
          };
          ns.post(options, function(succeed, data, err) {
              if (succeed) {
                  api.toast({
                      msg: '保存成功',
                      duration: 500,
                      location: 'bottom'
                  });
                  that.isActive = false;
                  that.dynamicData = false;
                  that.staticData = true;
                  setTimeout(function() {
                      api.sendEvent({
                          name: 'save_succeed',
                          extra: {
                              isupdate: true
                          }
                      });
                  }, 500);
                  setTimeout(function() {
                      api.closeWin();
                  }, 500);
              } else if (err) {
                  api.toast({
                      msg: err,
                      duration: 10000,
                      location: 'bottom'
                  });
              }
          });
        },
        cancel: function() {
            var that = this;
            that.isSearch = !that.isSearch;
        },
        tel_phone: function(phonenumber) {
            api.call({
                type: 'tel_prompt',
                number: phonenumber
            });
        },
        get_data: function(data, op) {
            var that = this;
            ns.post({
                ID: that.ID,
                action: 'viewroomfilebyroomid'
            }, function(succeed, data, err) {
                if (succeed) {
                    that.roominfo = data.room;
                    that.statelist = data.statelist;
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            })
        },
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    if (api.pageParam.id) {
        app.ID = api.pageParam.id;
        app.get_data();
    }
    api.addEventListener({
        name: 'do_open_edit'
    }, function(ret, err){
        if( ret ){
            app.edit();
        }
    });
}
